package com.cmnit.utils

import java.util.Date

object ServiceUtils {
  /**
   * 获取指定时间对象上一个小时的年月日时
   *
   * @param date 日期对象
   * @return
   */
  def getLastHour(date: Date): String = {
    val hour = DateUtils.getLastHour(date)
    val day = DateUtils.getLastHourOfDay(date)
    val month = DateUtils.getLastHourOfMonth(date)
    val year = DateUtils.getLastHourOfYear(date)
    year + "," + month + "," + day + "," + hour
  }

  /**
   * 获取账期时间，若不指定时间则默认前一个小时
   *
   * @param year  年
   * @param month 月
   * @param day   日
   * @param hour  小时
   * @return
   */
  def getAcctDate(year: String, month: String, day: String, hour: String): String = {
    var time = getLastHour(new Date)
    if (year != "" && month != "" && day != "" && hour != "") {
      time = year + "," + month + "," + day + "," + hour
    }
    time
  }
}
